﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace WindowsFormsApplication1
{

    public class Mydb
    {
        public static string exePath = System.Environment.CurrentDirectory;//本程序所在路径
        public OleDbConnection conn = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=" + exePath + @"\guest.mdb");

        public Mydb()
        {
            //创建连接对象
            conn.Open();
        }

        public void coleconn() 
        {
            conn.Close();
        }

        public DataTable getG_Fault2(string where)
        {

            string sql = "select * from G_problem where G_Type = \""+ where + "\"";

            OleDbDataAdapter da = new OleDbDataAdapter(sql, conn); //创建适配对象
            DataTable dt = new DataTable(); //新建表对象
            da.Fill(dt); //用适配对象填充表对象
            return dt;
        }

        public DataTable getG_Fault(string where) 
        {

            string sql = "select * from G_problem where G_id = " + where ;

            OleDbDataAdapter da = new OleDbDataAdapter(sql, conn); //创建适配对象
            DataTable dt = new DataTable(); //新建表对象
            da.Fill(dt); //用适配对象填充表对象
            return dt;
        }

        public DataTable getDT(string ziduan, string form, string where)
        {

            string sql = "select " + ziduan + " from " + form + " " + where;

            OleDbDataAdapter da = new OleDbDataAdapter(sql, conn); //创建适配对象
            DataTable dt = new DataTable(); //新建表对象
            da.Fill(dt); //用适配对象填充表对象
            return dt;


        }

        public DataTable getProblemType(string id)
        {

            string sql = "select * from G_problemType where G_id= " + id;

            OleDbDataAdapter da = new OleDbDataAdapter(sql, conn); //创建适配对象
            DataTable dt = new DataTable(); //新建表对象
            da.Fill(dt); //用适配对象填充表对象
            return dt;

        }

        public void insertProblem(string str1, string str2, string str3,string img) 
        {

            string sql = "insert into G_problem (G_Type ,G_Name ,G_Img ,G_Fault) VALUES ('" + str1 + "','" + str2 + "','" + img + "','" + str3 + "')";

            OleDbCommand cmd = new OleDbCommand(sql, conn); //定义Command对象
            //将账号密码存入数据库

            cmd.ExecuteNonQuery(); //执行Command命令

        }
        public void insertProblemType(string str1,string str2)
        {

            string sql = "insert into G_problemType (G_name ,G_sorting) VALUES ('" + str1 + "','" + str2 + "')";

            OleDbCommand cmd = new OleDbCommand(sql, conn); //定义Command对象
            //将账号密码存入数据库

            cmd.ExecuteNonQuery(); //执行Command命令

        }
        public void updateProblemType(string id, string names)
        {

            string sql = "update G_problemType set G_name = '" + names + "' where G_ID = " + id;

            OleDbCommand cmd = new OleDbCommand(sql, conn); //定义Command对象
            //将账号密码存入数据库

            cmd.ExecuteNonQuery(); //执行Command命令

        }
        public void deleteProblemType(string str1)
        {

            string sql = "delete from G_problemType where G_ID="+str1;

            OleDbCommand cmd = new OleDbCommand(sql, conn); //定义Command对象
            //将账号密码存入数据库

            cmd.ExecuteNonQuery(); //执行Command命令

        }
        public void deleteProblem(string str1)
        {

            string sql = "delete from G_problem where G_ID=" + str1;

            OleDbCommand cmd = new OleDbCommand(sql, conn); //定义Command对象
            //将账号密码存入数据库

            cmd.ExecuteNonQuery(); //执行Command命令

        }
        public void updateProblem(string id, string names, string conntxt,string img) 
        {

            string sql = "update G_problem set G_Name = '" + names + "',G_Fault = '" + conntxt + "',G_Img = '" + img + "' where G_ID = " + id;

            OleDbCommand cmd = new OleDbCommand(sql, conn); //定义Command对象
            //将账号密码存入数据库

            
            cmd.ExecuteNonQuery(); //执行Command命令

        }

        public static string nachu(string str) 
        {

            str = str.Replace("[^]", "'");
            str = str.Replace("&nbsp;", " ");
            str = str.Replace("&amp;", "&");
            str = str.Replace("&lt;", "<");
            str = str.Replace("&gt;", ">");
            str = str.Replace("</p>", "");
            str = str.Replace("<p>", "");
            str = str.Replace("<br>", "\r\n");
            str = str.Replace("&quot;", "\"");

            str = str.Replace("&NBSP;", " ");
            str = str.Replace("</P>", "");
            str = str.Replace("<P>", "");
            str = str.Replace("<BR>", "\r\n");
            str = str.Replace("&AMP;", "&");
            str = str.Replace("&LT;", "<");
            str = str.Replace("&GT;", ">");
            str = str.Replace("&QUOT;", "\"");
            return str;
        }

    }
}
